# -*- coding: utf-8 -*-
# @Time    : 2024/12/1 下午8:46
# @Author  : wjx
# @Email   : kanxinxin@163.com
# @File    : my_page.py
# @Software: PyCharm
from appium.webdriver.common.appiumby import AppiumBy as By
from pages.base_page import BasePage


class MyPage(BasePage):
    # 定位器
    # 菜谱
    cookbook_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().className('
                                                '"androidx.appcompat.app.ActionBar$Tab").instance(0)')
    # 作品
    works_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().className('
                                             '"androidx.appcompat.app.ActionBar$Tab").instance(1)')
    # 选择第一个菜谱
    select_first_cookbook_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                             '"com.xiachufang:id/item_img").instance(0)')
    # 写评论按钮
    write_assess_btn_locator = (By.ANDROID_UIAUTOMATOR,  'new UiSelector().resourceId('
                                                         '"com.xiachufang:id/recipe_bto_nav_bar_comment_btn")')
    # 写评论
    write_assess_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                    '"com.xiachufang:id/eidt_comment_content")')
    send_locator = (By.XPATH, '//android.widget.TextView[@resource-id="com.xiachufang:id/tv_comment_publish_btn"]')

    # 选择第一个作品
    select_first_works_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                                          '"com.xiachufang:id/iv_dish").instance(0)')
    # 点击三个点
    select_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId('
                                              '"com.xiachufang:id/common_control_panel_more_btn").instance(0)')
    # 点击删除
    delete_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().text("删除")')
    # 确认删除
    sure_delete_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("android:id/button1")')
    # 获取时间
    time_locator = (By.ANDROID_UIAUTOMATOR,'new UiSelector().resourceId("com.xiachufang:id/feed_dish_date")')
    def click_cookbook_btn(self):
        """
        点击菜谱
        :return:None
        """
        self.find_element(self.cookbook_locator).click()

    def click_works(self):
        """
        点击作品
        :return:None
        """
        self.find_element(self.works_locator).click()

    def click_select_first_cookbook(self):
        """
        点击选择第一个菜谱
        :return: None
        """
        self.find_element(self.select_first_cookbook_locator).click()

    def click_write_assess_btn(self):
        """
        点击写评论
        :return:None
        """
        self.find_element(self.write_assess_btn_locator).click()

    def input_write_assess(self,content):
        """
        写评论
        :param content:
        :return: None
        """
        self.find_element(self.write_assess_locator).send_keys(content)

    def click_send(self):
        """
        点击发送
        :return:None
        """
        self.find_element(self.send_locator).click()

    def click_select_first_works(self):
        """
        点击第一个作品
        :return: None
        """
        self.find_element(self.select_first_works_locator).click()

    def click_select(self):
        """
        点击作品右上角三个点
        :return: None
        """
        self.find_element(self.select_locator).click()

    def click_delete(self):
        """
        点击删除
        :return:None
        """
        self.find_element(self.delete_locator).click()

    def click_sure_delete(self):
        """
        弹窗确认删除
        :return: None
        """
        self.find_element(self.sure_delete_locator).click()

    def get_time(self):
        """
        获取时间
        :return:时间
        """
        return self.find_element(self.time_locator).text
